//
//  PopMenuListView.m
//  JiaoX
//
//  Created by yinqy on 15/2/27.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "PopMenuListView.h"
#import "MenuItemView.h"

@interface PopMenuListView()
{
    NSMutableArray *_btnArray;
}

@end
@implementation PopMenuListView

-(instancetype)initWithItemArray:(NSArray *)itemArray{
    self = [super init];
    if (self) {
        _btnArray = [NSMutableArray array];
        CGFloat y = 0;
        for (int i = 0; i<itemArray.count; i++) {
            PopMenuBean *bean = itemArray[i];
            MenuItemView *btn = [[MenuItemView alloc]initWithPopMenuBean:bean];
            [btn addTarget:self action:@selector(menuClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setY:y];[btn setTag:i];
            [self addSubview:btn];
            y = CGRectGetMaxY(btn.frame);
            if (i!=itemArray.count-1) {
                UIView *splite = [[UIView alloc]init];
                [splite setBackgroundColor:JXColor(204, 204, 204)];
                [splite setSize:CGSizeMake(MTV_WIDTH, 0.5)];
                [splite setY:y];
                [self addSubview:splite];
                y = CGRectGetMaxY(splite.frame);
            }
            [_btnArray addObject:btn];
        }
        [self setSize:CGSizeMake(MTV_WIDTH, y)];
    }
    return self;
}

-(void)updateChildItem{
    [_btnArray makeObjectsPerformSelector:@selector(updateItem)];
}

-(void)menuClick:(UIButton *)button{
    if ([self.delegate respondsToSelector:@selector(popMenuItemClick:)]) {
        [self.delegate popMenuItemClick:button.tag];
    }
}
@end
